package io.renren.modules.sys.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.entity.BusiBusinessEntity;
import io.renren.modules.sys.service.BusiBusinessService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-08-09 10:31:25
 */
@RestController
@RequestMapping("sys/busibusiness")
public class BusiBusinessController {
    @Autowired
    private BusiBusinessService busiBusinessService;

    /**
     * 获取验证码
     */
//    @RequestMapping("/verified")
//    public R verified(@RequestParam Map<String, Object> params){
////        busiBusinessService.insert();
//
//        return R.ok();
//    }


    /**
     * 订购业务
     */
//    @RequestMapping("/order")
//    public R order(@RequestParam Map<String, Object> params){
////        busiBusinessService.insert();
//
//        return R.ok();
//    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:busibusiness:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = busiBusinessService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:busibusiness:info")
    public R info(@PathVariable("id") Integer id){
        BusiBusinessEntity busiBusiness = busiBusinessService.selectById(id);

        return R.ok().put("busiBusiness", busiBusiness);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:busibusiness:save")
    public R save(@RequestBody BusiBusinessEntity busiBusiness){
        busiBusinessService.insert(busiBusiness);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:busibusiness:update")
    public R update(@RequestBody BusiBusinessEntity busiBusiness){
        ValidatorUtils.validateEntity(busiBusiness);
        busiBusinessService.updateAllColumnById(busiBusiness);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:busibusiness:delete")
    public R delete(@RequestBody Integer[] ids){
        busiBusinessService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
